import React from 'react';
import { BrowserRouter, Route, Switch } from 'dva/router';
import dynamic from 'dva/dynamic';
import "./Common.less"
import { TransitionGroup, CSSTransition } from 'react-transition-group'
const menuGlobal = [
    {
        id: 'index',
        pid: '0',
        name: '首页',
        icon: 'user',
        path: '/',
        models: () => [
            import('./models/design/workspace'),
            import('./models/design/menus'),
            import('./models/design/project'),
            import('./models/design/refRoads'),
            import('./models/design/bridge'),
            import('./models/design/refSpans'),
            import('./models/design/prop'),
            import('./models/design/structure'),
            import('./models/design/contextAction'),
            import('./models/design/dict'),
            import('./models/design/formular'),
            import('./models/design/cusProps'),
            import('./models/design/renforce'),
            import('./models/design/calculate'),
            import('./models/design/crossSection')
        ], //models可多个
        component: () => import('./views/project'),
    },
    {
        id: 'workspace',
        pid: '1',
        name: '设计页',
        icon: 'user',
        path: '/design',
        models: () => [
            import('./models/design/workspace'),
            import('./models/design/menus'),
            import('./models/design/project'),
            import('./models/design/refRoads'),
            import('./models/design/bridge'),
            import('./models/design/refSpans'),
            import('./models/design/prop'),
            import('./models/design/structure'),
            import('./models/design/contextAction'),
            import('./models/design/dict'),
            import('./models/design/formular'),
            import('./models/design/cusProps'),
            import('./models/design/renforce'),
            import('./models/design/calculate'),
            import('./models/design/crossSection')
        ], //models可多个
        component: () => import('./views/design'),
    },
    {
        id: 'structurelibrary',
        pid: '2',
        name: '族库管理',
        icon: 'user',
        path: '/libary',
        models: () => [
            import('./models/design/workspace'),
            import('./models/design/menus'),
            import('./models/design/project'),
            import('./models/design/refRoads'),
            import('./models/design/bridge'),
            import('./models/design/refSpans'),
            import('./models/design/prop'),
            import('./models/design/structure'),
            import('./models/design/contextAction'),
            import('./models/design/dict'),
            import('./models/design/formular'),
            import('./models/design/cusProps'),
            import('./models/design/renforce'),
            import('./models/design/calculate'),
            import('./models/design/crossSection')
        ], //models可多个
        component: () => import('./views/structureLibrary'),
    },
    {
        id: 'login',
        pid: '3',
        name: '登录',
        icon: 'user',
        path: '/login',
        models: () => [
            import('./models/design/workspace'),
            import('./models/design/menus'),
            import('./models/design/project'),
            import('./models/design/refRoads'),
            import('./models/design/bridge'),
            import('./models/design/refSpans'),
            import('./models/design/prop'),
            import('./models/design/structure'),
            import('./models/design/contextAction'),
            import('./models/design/dict'),
            import('./models/design/formular'),
            import('./models/design/cusProps'),
            import('./models/design/renforce'),
            import('./models/design/calculate'),
            import('./models/design/crossSection')
        ], //models可多个
        component: () => import('./views/user/login/login'),
    },
    {
        id: 'cusProps',
        pid: '4',
        name: '自定义属性',
        icon: 'user',
        path: '/cusProps',
        models: () => [
            import('./models/design/workspace'),
            import('./models/design/menus'),
            import('./models/design/project'),
            import('./models/design/refRoads'),
            import('./models/design/bridge'),
            import('./models/design/refSpans'),
            import('./models/design/prop'),
            import('./models/design/structure'),
            import('./models/design/contextAction'),
            import('./models/design/dict'),
            import('./models/design/formular'),
            import('./models/design/cusProps'),
            import('./models/design/renforce'),
            import('./models/design/calculate'),
            import('./models/design/crossSection')
        ], //models可多个
        component: () => import('./views/customProps'),
    },
    {
        id: 'structure',
        pid: '5',
        name: '自定义属性',
        icon: 'user',
        path: '/structure/:mode/:id/:definitionTreeId',
        models: () => [
            import('./models/design/workspace'),
            import('./models/design/menus'),
            import('./models/design/project'),
            import('./models/design/refRoads'),
            import('./models/design/bridge'),
            import('./models/design/refSpans'),
            import('./models/design/prop'),
            import('./models/design/structure'),
            import('./models/design/contextAction'),
            import('./models/design/dict'),
            import('./models/design/formular'),
            import('./models/design/cusProps'),
            import('./models/design/renforce'),
            import('./models/design/calculate'),
            import('./models/design/crossSection')
        ], //models可多个
        component: () => import('./views/structure'),
    },
    {
        id: 'renforce',
        pid: '8',
        name: '配筋',
        icon: 'user',
        path: '/renforce',
        models: () => [
            import('./models/design/workspace'),
            import('./models/design/menus'),
            import('./models/design/project'),
            import('./models/design/refRoads'),
            import('./models/design/bridge'),
            import('./models/design/refSpans'),
            import('./models/design/prop'),
            import('./models/design/structure'),
            import('./models/design/contextAction'),
            import('./models/design/dict'),
            import('./models/design/formular'),
            import('./models/design/cusProps'),
            import('./models/design/renforce'),
            import('./models/design/calculate'),
            import('./models/design/crossSection')
        ], //models可多个
        component: () => import('./views/renforce'),
    },
    {
        id: 'continuousRigidFrame',
        pid: '9',
        name: '大跨径连续钢构',
        icon: 'user',
        path: '/continuousRigidFrame',
        models: () => [
            import('./models/design/workspace'),
            import('./models/design/menus'),
            import('./models/design/project'),
            import('./models/design/refRoads'),
            import('./models/design/bridge'),
            import('./models/design/refSpans'),
            import('./models/design/prop'),
            import('./models/design/structure'),
            import('./models/design/contextAction'),
            import('./models/design/dict'),
            import('./models/design/formular'),
            import('./models/design/cusProps'),
            import('./models/design/renforce'),
            import('./models/design/calculate'),
            import('./models/design/crossSection')
        ], //models可多个
        component: () => import('./components/forms/continuousRigidFrame'),
    },
    {
        id: 'crossSection',
        pid: '10',
        name: '截面库管理',
        icon: 'user',
        path: '/crossSection',
        models: () => [
            import('./models/design/workspace'),
            import('./models/design/menus'),
            import('./models/design/project'),
            import('./models/design/refRoads'),
            import('./models/design/bridge'),
            import('./models/design/refSpans'),
            import('./models/design/prop'),
            import('./models/design/structure'),
            import('./models/design/contextAction'),
            import('./models/design/dict'),
            import('./models/design/formular'),
            import('./models/design/cusProps'),
            import('./models/design/renforce'),
            import('./models/design/calculate'),
            import('./models/design/crossSection')
        ], //models可多个
        component: () => import('./views/crossSection'),
    },
    {
        id: 'crossSectionDetail',
        pid: '11',
        name: '自定义属性',
        icon: 'user',
        path: '/crossSectionDetail/:mode/:id/:definitionTreeId',
        models: () => [
            import('./models/design/workspace'),
            import('./models/design/menus'),
            import('./models/design/project'),
            import('./models/design/refRoads'),
            import('./models/design/bridge'),
            import('./models/design/refSpans'),
            import('./models/design/prop'),
            import('./models/design/structure'),
            import('./models/design/contextAction'),
            import('./models/design/dict'),
            import('./models/design/formular'),
            import('./models/design/cusProps'),
            import('./models/design/renforce'),
            import('./models/design/calculate'),
            import('./models/design/crossSection')
        ], //models可多个
        component: () => import('./views/crossSectionDetail'),
    },
    
];

function RouterConfig({ history, app }) {

    return (
        <TransitionGroup>
            <CSSTransition key={location.key} timeout={1000} classNames="fade">
                <BrowserRouter basename={process.env.NODE_ENV=="production"?"/srd":""} history={history}>
                    <Switch >
                        {menuGlobal.map(({ path, ...dynamics }, index) => (
                            <Route
                                key={index}
                                path={path}
                                exact
                                onUpdate={
                                    document.title = "智能桥梁设计"
                                }
                                component={dynamic({
                                    app,
                                    ...dynamics
                                })}
                            >
                            </Route>
                        ))}
                    </Switch>

                </BrowserRouter>
            </CSSTransition>
        </TransitionGroup>
    );
}

export default RouterConfig;